package outoforder.leetcode;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-03-23 12:12
 */
public class Solutionali {
    public char[] reverseWords(char[] s) {
        char[] arr = new char[s.length];
        int po = 0;
        for(char ch : s){
            arr[s.length-1-po] = ch;
            po++;
        }
        s = arr;
        int le = 0;
        for(int i = 0;i < s.length-1; ){
            while(s[i] != ' ' && i < s.length-1){
                i++;
            }
            if (i==s.length-1) i++;
            for(int j = 0; j < (i-le)/2;j++){
                char temp = s[le+j];
                s[le+j] = s[i-j-1];
                s[i-j-1] = temp;
            }
            le = i+1;
            i++;
        }
        return s;
    }
    @Test
    public void test(){
        Solutionali solutionali = new Solutionali();
        char[] chars = solutionali.reverseWords(new char[]{'t', 'h', 'e', ' ', 's', 'k', 'y', ' ', 's', 'i', ' ', 'b', 'l', 'u', 'e'});
        for (char ch : chars){
            System.out.print(ch);
        }

    }
}
